﻿<common:LayoutAwarePage
    x:Name="pageRoot"
    x:Class="Music.HubPage"
    DataContext="{Binding DefaultViewModel, RelativeSource={RelativeSource Self}}"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:Music"
    xmlns:Data="using:Music.Data"
    xmlns:tiles="using:Music.VariableTemplate"
    xmlns:common="using:Music.Common"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">
    
    <Page.TopAppBar>
        <AppBar x:Name="TopAppBar" Height="140" Background="#DD000000">
        	<common:TopAppBar x:Name="TopBar" HorizontalAlignment="Left" VerticalAlignment="Center"/>
        </AppBar>
    </Page.TopAppBar>

    <Page.Resources>

        <!--
            Collection of grouped items displayed by this page, bound to a subset
            of the complete item list because items in groups cannot be virtualized
        -->
        <CollectionViewSource
            x:Name="groupedItemsViewSource"
            Source="{Binding Groups}"
            IsSourceGrouped="true"
            ItemsPath="TopItems"
            d:Source="{Binding AllGroups,Source={d:DesignInstance Type=Data:HubPageDataSource,IsDesignTimeCreatable=True}}"/>

        <CollectionViewSource
            x:Name="groupedItemsViewSource2"
            Source="{Binding Groups2}"
            IsSourceGrouped="true"
            ItemsPath="TopItems"
            d:Source="{Binding AllGroups,Source={d:DesignInstance Type=Data:PlaylistDataSource,IsDesignTimeCreatable=True}}"/>

        <DataTemplate x:Key="FeaturedTemplate">
            <Grid Width="630" Height="120" Background="#FFededed">
                <GridView Padding="10,2,0,0"
            x:Name="itemGridView"
            AutomationProperties.AutomationId="ItemGridView" ScrollViewer.HorizontalScrollBarVisibility="Disabled"
            AutomationProperties.Name="Grouped Items"                    
            ItemsSource="{Binding Source={StaticResource groupedItemsViewSource2}}"
            ItemTemplate="{StaticResource PlayListDataTemplate}"
            SelectionMode="None"  ItemContainerStyle="{StaticResource PlaylistContainerStyle}"
            IsSwipeEnabled="false"
            IsItemClickEnabled="True">

                    <GridView.ItemsPanel>
                        <ItemsPanelTemplate>
                            <VirtualizingStackPanel Orientation="Horizontal"/>
                        </ItemsPanelTemplate>
                    </GridView.ItemsPanel>
                    <GridView.GroupStyle>
                        <GroupStyle>
                            <GroupStyle.HeaderTemplate>
                                <DataTemplate>
                                    <Grid Margin="-3,-10,0,0">
                                        <Button Foreground="Black"
                                    AutomationProperties.Name="Group Title"                                    
                                    Style="{StaticResource TextPrimaryButtonStyle}" >
                                            <StackPanel Orientation="Horizontal">
                                                <TextBlock Text="{Binding Title}" Margin="3,-7,10,10" Style="{StaticResource GroupHeaderTextStyle}" FontSize="12" FontWeight="Normal"/>                                                
                                            </StackPanel>
                                        </Button>
                                    </Grid>
                                </DataTemplate>
                            </GroupStyle.HeaderTemplate>
                            <GroupStyle.Panel>
                                <ItemsPanelTemplate>
                                    <VariableSizedWrapGrid Orientation="Vertical" Margin="0,0,105,0"/>
                                </ItemsPanelTemplate>
                            </GroupStyle.Panel>
                        </GroupStyle>
                    </GridView.GroupStyle>
                </GridView>
            </Grid>
        </DataTemplate>

        <DataTemplate x:Key="BigFeaturedTemplate">
            <Grid Width="630" Height="370" VerticalAlignment="Center">
                <Grid.RowDefinitions>
                    <RowDefinition/>
                    <RowDefinition Height="44"/>
                </Grid.RowDefinitions>
                <Image Grid.RowSpan="2" Source="{Binding Image}" Stretch="UniformToFill"/>
                <Slider VerticalAlignment="Bottom" Style="{StaticResource SeekBarSliderStyle}" Foreground="#FFD72537" BorderBrush="Black" BorderThickness="1" Value="70" Height="36" Margin="14,0"/>
                <Grid Grid.Row="1" Background="#FFEDEDED">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="12"/>
                        <ColumnDefinition/>
                        <ColumnDefinition Width="2*"/>
                        <ColumnDefinition/>
                        <ColumnDefinition Width="12"/>
                    </Grid.ColumnDefinitions>
                    <StackPanel Grid.Column="1" Orientation="Horizontal" VerticalAlignment="Center">
                        <TextBlock HorizontalAlignment="Left" TextWrapping="Wrap" Text="Volume" VerticalAlignment="Center" Foreground="Black" FontFamily="Segoe UI" FontSize="13.333"/>
                        <Slider Width="56" VerticalAlignment="Center" Margin="5,0" Style="{StaticResource VolumeSliderStyle}" Foreground="White" BorderBrush="Black" BorderThickness="1" Value="70" Height="36"/>
                    </StackPanel>
                    <StackPanel Grid.Column="2" Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
                        <Button Tag="{StaticResource Previous}" Foreground="Black" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Style="{StaticResource PrevNextBtnStyle}" Width="27" Height="11" Margin="5,0"/>
                        <CheckBox Content="CheckBox" HorizontalAlignment="Center" Style="{StaticResource PlayPauseChkBoxStyle}" VerticalAlignment="Center" IsChecked="False"/>
                        <Button Tag="{StaticResource Next}" Foreground="Black" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Style="{StaticResource PrevNextBtnStyle}" Width="27" Height="11" Margin="5,0"/>
                    </StackPanel>
                    <CheckBox Content="FullScreen" HorizontalAlignment="Right" VerticalAlignment="Center" Grid.Column="3" Foreground="Black" Style="{StaticResource FullScreenChkBoxStyle}" FontSize="13.333"/>
                </Grid>
            </Grid>
        </DataTemplate>

        <tiles:VariableTiles x:Key="MyTemplates"
                             BigFeaturedTemplate="{StaticResource BigFeaturedTemplate}"
                             FeaturedTemplate="{StaticResource FeaturedTemplate}"
                             NormalTemplate="{StaticResource NormalTemplate}">
        </tiles:VariableTiles>        
        <tiles:VariableStyles x:Key="MyStyles"/>

        <!-- TODO: Delete this line if the key AppName is declared in App.xaml -->
        <x:String x:Key="AppName">My Application</x:String>
    </Page.Resources>

    <!--
        This grid acts as a root panel for the page that defines two rows:
        * Row 0 contains the back button and page title
        * Row 1 contains the rest of the page layout
    -->
    <Grid Style="{StaticResource LayoutRootStyle}">
    	<Grid.Background>
    		<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
    			<GradientStop Color="#FFD52339"/>
    			<GradientStop Color="#FFE93826" Offset="1"/>
    		</LinearGradientBrush>
    	</Grid.Background>
        <Grid.RowDefinitions>
            <RowDefinition Height="140"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
 
        <!-- Horizontal scrolling grid used in most view states -->
        
        <ScrollViewer x:Name="MainScroll" Grid.RowSpan="2" Style="{StaticResource HorizontalScrollViewerStyle}">           
            <tiles:VariableTileControl
            x:Name="itemGridView"
            AutomationProperties.AutomationId="itemGridView"
            AutomationProperties.Name="Grouped Items"
            Grid.RowSpan="2"        IsItemClickEnabled="True" ItemClick="itemGridView_ItemClick_1"
            Padding="116,137,40,46"
            ItemsSource="{Binding Source={StaticResource groupedItemsViewSource}}"
            ItemTemplateSelector="{StaticResource MyTemplates}"
            SelectionMode="None"
            IsSwipeEnabled="false" ItemContainerStyleSelector="{StaticResource MyStyles}">

                <tiles:VariableTileControl.ItemsPanel>
                    <ItemsPanelTemplate>
                        <VirtualizingStackPanel Orientation="Horizontal" Margin="0,0,120,0"/>
                    </ItemsPanelTemplate>
                </tiles:VariableTileControl.ItemsPanel>
                <tiles:VariableTileControl.GroupStyle>
                    <GroupStyle>
                        <GroupStyle.HeaderTemplate>
                            <DataTemplate>
                                <Grid Margin="1,0,0,6">
                                    <Button Click="Header_Click" Tag="{Binding UniqueId}"
                                    AutomationProperties.Name="Group Title"
                                    Style="{StaticResource TextPrimaryButtonStyle}">
                                        <StackPanel Orientation="Horizontal">
                                            <TextBlock Text="{Binding Title}" Margin="3,0,10,10" Style="{StaticResource GroupHeaderTextStyle}" FontSize="30"/>
                                            <Path Width="38" Height="38" Stretch="Fill" Fill="White" Data="{StaticResource HeaderNext}"/>
                                            <!--<TextBlock Text="{StaticResource ChevronGlyph}" FontFamily="Segoe UI Symbol" Margin="0,-7,0,10" Style="{StaticResource GroupHeaderTextStyle}"/>-->
                                        </StackPanel>
                                    </Button>
                                </Grid>
                            </DataTemplate>
                        </GroupStyle.HeaderTemplate>
                        <GroupStyle.Panel>
                            <ItemsPanelTemplate>
                                <VariableSizedWrapGrid ItemHeight="10" ItemWidth="10" Orientation="Vertical" MaximumRowsOrColumns="51" Margin="0,0,30,0"/>
                            </ItemsPanelTemplate>
                        </GroupStyle.Panel>
                    </GroupStyle>
                </tiles:VariableTileControl.GroupStyle>
            </tiles:VariableTileControl>   
        </ScrollViewer>
        
        <!-- Vertical scrolling list only used when snapped -->
        <ListView
            x:Name="itemListView"
            AutomationProperties.AutomationId="ItemListView"
            AutomationProperties.Name="Grouped Items"
            Grid.Row="1"
            Visibility="Collapsed"
            Margin="0,-10,0,0"
            Padding="10,0,0,60" IsItemClickEnabled="True" ItemClick="itemGridView_ItemClick_1"
            ItemsSource="{Binding Source={StaticResource groupedItemsViewSource}}"
            ItemTemplate="{StaticResource Standard80ItemTemplate}"
            SelectionMode="None"
            IsSwipeEnabled="false">

            <ListView.GroupStyle>
                <GroupStyle>
                    <GroupStyle.HeaderTemplate>
                        <DataTemplate>
                            <Grid Margin="7,7,0,0">
                                <Button Click="Header_Click" Tag="{Binding UniqueId}"
                                    AutomationProperties.Name="Group Title"
                                    Style="{StaticResource TextPrimaryButtonStyle}">
                                    <StackPanel Orientation="Horizontal">
                                        <TextBlock Text="{Binding Title}" Margin="3,-7,10,10" Style="{StaticResource GroupHeaderTextStyle}" />
                                        <TextBlock Text="{StaticResource ChevronGlyph}" FontFamily="Segoe UI Symbol" Margin="0,-7,0,10" Style="{StaticResource GroupHeaderTextStyle}"/>
                                    </StackPanel>
                                </Button>
                            </Grid>
                        </DataTemplate>
                    </GroupStyle.HeaderTemplate>
                </GroupStyle>
            </ListView.GroupStyle>
        </ListView>

        <!-- Back button and page title -->
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Button x:Name="backButton" Click="GoBack" IsEnabled="{Binding Frame.CanGoBack, ElementName=pageRoot}" Style="{StaticResource BackButtonStyle}"/>
            <Image x:Name="AppLogo" Source="Assets/AppLogo.png" Grid.Column="1" HorizontalAlignment="Right" Margin="40,0" Height="95"/>
            <TextBlock x:Name="pageTitle" Text="Your App slogan goes here" Grid.Column="1" IsHitTestVisible="false" Style="{StaticResource PageHeaderTextStyle}"/>
        </Grid>

        <VisualStateManager.VisualStateGroups>

            <!-- Visual states reflect the application's view state -->
            <VisualStateGroup x:Name="ApplicationViewStates">
                <VisualState x:Name="FullScreenLandscape"/>
                <VisualState x:Name="Filled"/>

                <!-- The entire page respects the narrower 100-pixel margin convention for portrait -->
                <VisualState x:Name="FullScreenPortrait">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PortraitBackButtonStyle}"/>
                        </ObjectAnimationUsingKeyFrames>

                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="itemGridView" Storyboard.TargetProperty="Padding">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="96,137,10,56"/>
                        </ObjectAnimationUsingKeyFrames>

                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="pageTitle" Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="AppLogo" Storyboard.TargetProperty="HorizontalAlignment">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Left"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="AppLogo" Storyboard.TargetProperty="Margin">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="0"/>
                        </ObjectAnimationUsingKeyFrames>

                    </Storyboard>
                </VisualState>

                <!--
                    The back button and title have different styles when snapped, and the list representation is substituted
                    for the grid displayed in all other view states
                -->
                <VisualState x:Name="Snapped">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SnappedBackButtonStyle}"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="itemListView" Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Visible"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="MainScroll" Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="TopAppBar" Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="pageTitle" Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="AppLogo" Storyboard.TargetProperty="HorizontalAlignment">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Left"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="AppLogo" Storyboard.TargetProperty="Margin">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="10,0,0,0"/>
                        </ObjectAnimationUsingKeyFrames>
                        
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
    </Grid>
</common:LayoutAwarePage>
